home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / irix / scripts / counts < prev    next >
Encoding:
Text File  |  1994-08-02  |  2.4 KB  |  88 lines

  1. #!/bin/csh -f
  2. #
  3. # $Id: counts.csh,v 1.2 1994/02/07 23:13:07 chrisc Exp $
  4. #
  5. # This shell script reads stdin (which should be one of the make.deps
  6. # in a source directory) and tells which header files are called by
  7. # which files.  Thus telling how many files *don't* call a particular
  8. # header file.
  9. #
  10. # The way I used it was I wanted to find out how many include files
  11. # from mdlgate were used.  I preformed a grep on make.deps:
  12. #    grep mdlgate make.deps
  13. # This told me that lots of files were included from mdlgate.  I then
  14. # needed to add the include file that redefines Fortran functions to
  15. # append an underscore to all the functions that include from mdlgate.
  16. # This script told me which mdlgate header file to add an include to
  17. # mdlgatef2c.h.
  18. #    grep mdlgate make.deps | counts.csh
  19. #
  20. # Revision History:
  21. #    $Log: counts.csh,v $
  22. # Revision 1.2  1994/02/07  23:13:07  chrisc
  23. # Modified to put the counts in files.  This helped because I ran out
  24. #   of argument space in some directories.
  25. #
  26. #--------------------------------------------------------------------
  27.  
  28. set noglob
  29.  
  30. set allincs = /usr/var/tmp/allincs$$
  31. set allfiles = /usr/var/tmp/allfiles$$
  32. set inclist = /usr/var/tmp/inclist$$
  33. set tmpFile = /usr/var/tmp/tmp$$
  34.  
  35. rm -f $allincs $allfiles $inclist
  36. touch $allincs
  37. touch $allfiles
  38. touch $inclist
  39.  
  40. @ totfiles = 0
  41. @ totincs = 0
  42.  
  43. while ( 1 )
  44.     set line = $<
  45.     if ( "$line" == "" ) break
  46.     set cline = `echo $line | sed 's/://'`
  47.     grep $cline[1] $allfiles >& /dev/null
  48.     if ( $status ) then
  49.     echo $cline[1] >> $allfiles
  50.     @ totfiles = $totfiles + 1
  51.     endif
  52.     set find = `grep -n $cline[2] $allincs`
  53.     if ( $status ) then
  54.     echo $cline[2] >> $allincs
  55.     @ totincs = $totincs + 1
  56.     echo $cline[1] >> $inclist
  57.     else
  58.     set n = `echo "$find[1]" | awk -F: '{print $1}'`
  59.     set x = `head -$n $inclist | tail -1`
  60.     echo "$x" | grep "$cline[1]" >& /dev/null
  61.     if ( $status ) then
  62.         @ n1 = $n - 1
  63.         head -$n1 $inclist > $tmpFile
  64.         echo "$x" "$cline[1]" >> $tmpFile
  65.         @ n1 = $totincs - $n
  66.         tail -$n1 $inclist >> $tmpFile
  67.         mv $tmpFile $inclist
  68.     endif
  69.     endif
  70. end
  71.  
  72. @ n = 0
  73. while ( $n < $totincs )
  74.     @ n = $n + 1
  75.     set x = `head -$n $inclist | tail -1`
  76.     set inc = `head -$n $allincs | tail -1`
  77.     set f = ()
  78.     foreach file ( `cat $allfiles` )
  79.     echo $x | grep $file >& /dev/null
  80.     if ( $status ) set f = ( $f $file )
  81.     end
  82.     echo "$inc is not called by $#f out of $totfiles files"
  83.     echo "     not called by $f"
  84.     echo ""
  85. end
  86.  
  87. rm $allincs $allfiles $inclist
  88.